package com.cat.greedyAlgorithm;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-split-of-positive-even-integers/description/
 * @create 2025/8/22 15:33
 * @since JDK17
 */

public class Solution13 {
    public List<Long> maximumEvenSplit(long finalSum) {
        if ((finalSum & 1) == 1) {
            return new ArrayList<Long>();
        }
        List<Long> ans = new ArrayList<>();
        for (long i = 2; finalSum > 0; i += 2) {
            if (finalSum < i) {
                ans.set(ans.size() - 1, ans.get(ans.size() - 1) + finalSum);
                return ans;
            } else {
                ans.add(i);
                finalSum -= i;
            }
        }

        return ans;
    }
}
